<template>
	<div class="editriji">
		<Header
		@goback="goback"
		@save="save"
		></Header>
		<EditRiQi
		ref="editriqi"
		@onEditorBlur="onEditorBlur"
		></EditRiQi>
	</div>
</template>

<script>
// eslint-disable-next-line
/* eslint-disable */
import EditRiQi from '../components/editriqi.vue'
import Header from '../components/Header.vue'
import { MessageBox } from "mint-ui"
export default {
	name: 'editriqi',
	components: {
		EditRiQi,
		Header
	},
	data() {
		return {
			diaryText:'',
		}
	},
	methods: {
		onEditorBlur($e,content){
			this.diaryText = content;
		},
		goback(){
			this.$router.go(-1)
		},
		save(){
			if(!this.diaryText){
				MessageBox("","请输入日记")
				return;
			}
			api.diary({
				user_id: localStorage.getItem("userid"),
				user_name: localStorage.getItem("username"),
				diary: this.diaryText,
				token: localStorage.getItem("token"),
			}).then(res=>{
				if(res.code===0){
					MessageBox("",res.message).then(action=>{
						if(action=="confirm"){
							this.$refs.editriqi.$refs.myQuillEditor.$el.children[1].firstChild.children[0].innerText = ""
						}
					})

				}
			}).catch(err=>{
				if(err.code===1009){
					MessageBox("",err.message);
				}
			})
		}
	}
}
</script>

<style scoped lang="scss">
@import "../../public/sass/var.scss";
.editriji{
	background-color: #666;
	color: #fff;
}
</style>